import time
import pyrealsense2 as rs
import cv2
import numpy as np


pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.color, 1920, 1080, rs.format.bgr8, 30)
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)
config.resolve(pipeline)
profile = pipeline.start(config)

avg_fps, cnt = 0, 0

while True:
    start_time = time.time()
    frame = pipeline.wait_for_frames()
    rgb = np.asanyarray(frame.get_color_frame().get_data())
    depth = np.asanyarray(frame.get_depth_frame().get_data())
    used_time = time.time() - start_time
    cnt += 1
    avg_fps += ((1 / used_time) - avg_fps) / cnt
    print(f"{avg_fps=}")
    cv2.imshow("rgb", rgb)
    cv2.waitKey(1)
